package com.leyou.common.adivce;

import com.leyou.common.exception.LyException;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @Author 张伟奇
 * @Date 2021/7/12 15:03
 * @description
 * @Version 1.0
 **/
@Slf4j
@ControllerAdvice
public class ControllerExceptionAdvice {
    @ExceptionHandler
    public ResponseEntity<String> handleLyException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }

    @ExceptionHandler
    public ResponseEntity<String> handleRunTimeException(RuntimeException ex){
        return ResponseEntity.status(500).body(ex.getMessage());
    }
}
